//
//  CarDataCalculate.m
//  STool
//
//  Created by Samuel on 15/9/10.
//
//

#import "CarDataCalculate.h"

@implementation CarDataCalculate
+ (NSMutableDictionary*)getInfoDataWithCarInfo:(CarInfo*)carinfo;
{
    NSMutableDictionary *arc = [[NSMutableDictionary alloc]init];
    
    [arc setObject:carinfo.carId forKey:@"carId"];
    [arc setObject:carinfo.carType forKey:@"carType"];
    [arc setObject:carinfo.carBuyTime forKey:@"buyTime"];
    [arc setObject:carinfo.glCost forKey:@"glCost"];
    [arc setObject:carinfo.glType forKey:@"glTypeCount"];
    
    return arc;
}

+ (NSMutableDictionary*)getRecordDataWithCarRecord:(CarRecord*)carrecord andLastCarRecord:(CarRecord*)lcarrecord;
{
    NSMutableDictionary *cdc = [[NSMutableDictionary alloc]init];
//    @property (nonatomic, retain) NSString * carType;//车型
//    @property (nonatomic, retain) NSString * carBuyTime;//车辆购买时间
//    @property (nonatomic, retain) NSString * glCost;//标准平均油耗
//    @property (nonatomic, retain) NSString * glType;//油号
//    
//    @property (nonatomic, retain) NSString * recordTime;//记录的时间（加油的时间）
//    @property (nonatomic, retain) NSString * alllKM;//总里程
//    @property (nonatomic, retain) NSString * thisMoneyCost;//加油花费
//    @property (nonatomic, retain) NSString * glUnitCost;//多少钱一升
//    @property (nonatomic, retain) NSString * averageGlCost;//平均油耗
    
    NSString *hundredKMCost = [NSString stringWithFormat:@"%.2f元",[carrecord.glUnitCost floatValue]*[carrecord.averageGlCost floatValue]];        //百公里价格
    NSString *hundredGLCost = [NSString stringWithFormat:@"%.2f升",[carrecord.averageGlCost floatValue]];        //百公里油耗
    NSString *thisGLLitre = [NSString stringWithFormat:@"%.2f升",[carrecord.thisMoneyCost floatValue]/[carrecord.glUnitCost floatValue]];          //此次购买油量
    NSString *timeToTime = (lcarrecord)?[NSString stringWithFormat:@"%@ 到 %@",lcarrecord.recordTime,carrecord.recordTime]:carrecord.recordTime;           //时间
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[carrecord.recordTime floatValue]];
    NSDateFormatter *dataFormatter = [[NSDateFormatter alloc]init];
    [dataFormatter setDateFormat:@"yyyy年MM月dd日 HH:mm"];
    [dataFormatter stringFromDate:confromTimesp]
    
    NSString *thisGLMoneyCost = [NSString stringWithFormat:@"%.2f元",[carrecord.thisMoneyCost floatValue]];      //油钱总价
    NSString *thisGLUnitMoneyCost = [NSString stringWithFormat:@"%.2f元",[carrecord.glUnitCost floatValue]];  //油钱单价
    NSString *thisAllKM = [NSString stringWithFormat:@"%d Km",[carrecord.alllKM intValue]];            //当前总里程
    NSString *lastAllKM = (lcarrecord)?lcarrecord.alllKM:@"暂无上次里程数据";            //上次总里程
    NSString *thisKM = [NSString stringWithFormat:@"%d Km",(int)MAX([thisAllKM floatValue]-((lcarrecord)?[lastAllKM floatValue]:0), 0)];               //此次里程数!!!!!
    NSString *thisGLCost = [NSString stringWithFormat:@"%.2f 升",[thisKM floatValue]/100*[carrecord.averageGlCost floatValue]];           //此次耗油量

    [cdc setObject:hundredKMCost forKey:@"hundredKMCost"];
    [cdc setObject:hundredGLCost forKey:@"hundredGLCost"];
    [cdc setObject:thisGLLitre forKey:@"thisGLLitre"];
    [cdc setObject:timeToTime forKey:@"timeToTime"];
    [cdc setObject:thisGLMoneyCost forKey:@"thisGLMoneyCost"];
    [cdc setObject:thisGLUnitMoneyCost forKey:@"thisGLUnitMoneyCost"];
    [cdc setObject:thisAllKM forKey:@"thisAllKM"];
    [cdc setObject:lastAllKM forKey:@"lastAllKM"];
    [cdc setObject:thisKM forKey:@"thisKM"];
    [cdc setObject:thisGLCost forKey:@"thisGLCost"];
    
    return cdc;
}
@end
